<template>
	<view class="al-navbar">
		<view :class="{'al-navbar--fixed': fixed,'al-navbar--shadow':shadow,'al-navbar--border':border}" :style="{'background-color':backgroundColor}" class="al-navbar__content">
			<status-bar v-if="statusBar" />
			<view :style="{color:color}" class="al-navbar__header al-navbar__content_view">
				<view class="al-navbar__header-btns al-navbar__content_view" @tap="onClickLeft">
					<view v-if="leftIcon.length" class="al-navbar__content_view">
						<icon-font :type="leftIcon" :color="color" size="18" />
					</view>
					<view v-if="leftText.length" :class="{'al-navbar-btn-icon-left':!leftIcon.length}" class="al-navbar-btn-text al-navbar__content_view">{{ leftText }}</view>
					<slot name="left" />
				</view>
				<view class="al-navbar__header-container al-navbar__content_view">
					<view v-if="title.length" class="al-navbar__header-container-inner al-navbar__content_view">{{ title }}</view>
					<!-- 标题插槽 -->
					<slot />
				</view>
				<view :class="title.length?'al-navbar__header-btns-right':''" class="al-navbar__header-btns al-navbar__content_view" @tap="onClickRight">
					<view v-if="rightIcon.length" class="al-navbar__content_view">
						<icon-font :type="rightIcon" :color="color" size="24" />
					</view>
					<!-- 优先显示图标 -->
					<view v-if="rightText.length&&!rightIcon.length" class="al-navbar-btn-text al-navbar__content_view">{{ rightText }}</view>
					<slot name="right" />
				</view>
			</view>
		</view>
		<view v-if="fixed" class="al-navbar__placeholder">
			<status-bar v-if="statusBar" />
			<view class="al-navbar__placeholder-view" />
		</view>
	</view>
</template>

<script>
	import statusBar from '@/components/status-bar.vue'
	export default {
		name: 'alNavBar',
		components:{
			statusBar
		},
		props: {
			title: {
				type: String,
				default: ''
			},
			leftText: {
				type: String,
				default: ''
			},
			rightText: {
				type: String,
				default: ''
			},
			leftIcon: {
				type: String,
				default: ''
			},
			rightIcon: {
				type: String,
				default: ''
			},
			fixed: {
				type: [Boolean, String],
				default: false
			},
			color: {
				type: String,
				default: '#000000'
			},
			backgroundColor: {
				type: String,
				default: '#FFFFFF'
			},
			statusBar: {
				type: [Boolean, String],
				default: true
			},
			shadow: {
				type: [String, Boolean],
				default: false
			},
			border: {
				type: [String, Boolean],
				default: true
			}
		},
		methods: {
			onClickLeft() {
				this.$emit('click-left')
			},
			onClickRight() {
				this.$emit('click-right')
			}
		}
	}
</script>

<style>
	@charset "UTF-8";

	.al-navbar__content {
		display: block;
		position: relative;
		width: 100%;
		background-color: #fff;
		overflow: hidden
	}

	.al-navbar__content .al-navbar__content_view {
		display: flex;
		align-items: center
	}

	.al-navbar__header {
		display: flex;
		flex-direction: row;
		width: 100%;
		height: 50px;
		line-height: 50px;
		font-size: 16px
	}

	.al-navbar__header-btns {
		display: inline-flex;
		flex-wrap: nowrap;
		flex-shrink: 0;
		width: 80rpx;
		padding: 0 12rpx
	}

	.al-navbar__header-btns:first-child {
		padding-left: 18rpx
	}

	.al-navbar__header-btns:last-child {
		width: 100rpx
	}

	.al-navbar__header-btns-right:last-child {
		width: 180rpx;
		text-align: right;
		flex-direction: row-reverse
	}

	.al-navbar__header-container {
		width: 100%;
		margin: 0 10rpx
	}

	.al-navbar__header-container-inner {
		width: 100%;
		display: flex;
		justify-content: center;
		font-size: 36rpx
	}

	.al-navbar__placeholder-view {
		height: 44px
	}

	.al-navbar--fixed {
		position: fixed;
		z-index: 998
	}

	.al-navbar--shadow {
		box-shadow: 0 1px 6px #ccc
	}

	.al-navbar--border:after {
		position: absolute;
		z-index: 3;
		bottom: 0;
		left: 0;
		right: 0;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #e5e5e5
	}
</style>